from django.test import TestCase
from rest_framework.test import APITestCase
from rest_framework import status
from .models import PhaseSummary

class PhaseSummaryTests(APITestCase):
    def test_create_summary(self):
        """测试生成阶段总结"""
        data = {
            "context": "人工智能产业，最近一个月，创新风格"
        }
        response = self.client.post('/api/v1/summary/generate/', data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(PhaseSummary.objects.count(), 1)
        self.assertEqual(response.data['code'], 200)

    def test_get_summary_list(self):
        """测试获取报告列表"""
        response = self.client.get('/api/v1/summary/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_get_summary_detail(self):
        """测试获取单个报告"""
        summary = PhaseSummary.objects.create(
            title="测试报告",
            content="测试内容",
            workflow_name=1
        )
        response = self.client.get(f'/api/v1/summary/{summary.id}/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['title'], "测试报告") 